public class test3 {
    public static void main(String[] args) {
       //方法1
        /* double i = 1;
        double sum = 0;
        while (i <= 100) {
            if(i % 2 != 0) {
                sum = sum + 1 / i;
            }else {
                sum = sum - 1 / i;
            }
            i++;
        }
        System.out.println(sum);*/

//方法2
            double sum = 0;
            int flg = 1;
            for (int i = 1; i <= 100; i++) {
                sum += 1.0/i * flg;
                flg = -flg;
            }
            System.out.println(sum);

    }
}
